<template>
<slot :controller="controller" :store="store" :model="model">
    <AppMDViewLayout :class="classNames" :openType="openType">
		<template #viewHeaderContentLeft v-if="model.showCaption && !noViewCaption" >
			<div class="view-header__caption">
				<slot name="ViewCaption" :controller="controller" :store="store" :model="model">
				    <AppCaptionBar :caption="model.caption" :title="model.title" :capPSLanguageRes="model.capPSLanguageRes" :titlePSLanguageRes="model.titlePSLanguageRes" :openType="openType"></AppCaptionBar>
				</slot>
			</div>
		</template>
		<template v-slot:[searchFormSlotName]>
			<slot name="IBIZCustomerDefaultSearchForm" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
			    <IBIZCustomerDefaultSearchForm
			        :actions="{
			            loadDraftAction: 'GetDraft'
			        }"
			        name="searchform"
			        v-bind="model.ctrlParams.IBIZCustomersearchform"
			        :context="store.context"
			        :viewParams="store.viewParams"
			        :closeView="store.closeView"
			        :pLoadingHelper="store.loadingHelper"
			        :pViewCtx="store.viewCtx"
			        @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
			        @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
			        @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"    />
			</slot>
		</template>
    	<template #default>
			<slot name="IBIZCustomerMainGrid" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
			<IBIZCustomerMainGrid
			    
			    :actions="{
			        loadDraftAction: 'GetDraft',
			        createAction: 'Create',
			        fetchAction: 'FetchDefault',
			        removeAction: 'Remove',
			        updateAction: 'Update'
			    }"
			    :defaultEnableRowEdit="model.rowEditDefault"
			    :openView="store.openView"
			    :newView="store.newView"
			    :singleSelect="singleSelect"
			    name="grid"
			    v-bind="model.ctrlParams.IBIZCustomergrid"
			    :context="store.context"
			    :viewParams="store.viewParams"
			    :closeView="store.closeView"
			    :pLoadingHelper="store.loadingHelper"
			    :pViewCtx="store.viewCtx"
			    @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
			    @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
			    @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"></IBIZCustomerMainGrid>
			</slot>
		</template>
    </AppMDViewLayout>
</slot>
</template>
<script setup lang="ts">
// 基于template/src/views/{{appModules}}/{{pages@DEPICKUPGridView}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppMDViewLayout } from '@components/layout/md-view-layout';
import IBIZCustomerDefaultSearchForm from '@widgets/ibiz-customer/default-searchform/default-searchform.vue';
import IBIZCustomerMainGrid from '@widgets/ibiz-customer/main-grid/main-grid.vue';
import { IEvent, IParam, IPickupGridViewAbility, IPickupGridViewStore, PickupGridViewActionType } from "@/core";
import { useProps, useBasic, useAction, useController } from './ibiz-customer-pickup-grid-view-hook';

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { getClassNames, getSearchFormSlotName, model, 
	useNavParamsBind,
	useEventBind,
  	handleQuickGroupValueChange,
  	handleQuickSearch,
  	handleToolbarItemClick,
    handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy 
} = useBasic(props);

const emit = defineEmits<{
    (event: 'view-action', name: string, action: PickupGridViewActionType, data: IParam[]): void;
    (event: 'view-init', name: string, data: IPickupGridViewAbility): void;
    (event: 'view-mounted', name: string, data: IParam): void;
    (event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  	return getClassNames(props);
});

const searchFormSlotName = computed(() => {
  	return getSearchFormSlotName(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IPickupGridViewStore = controller.getStore();

onMounted(() => {
    controller.viewMounted();
})

onUnmounted(() => {
    controller.viewDestroy();
})
</script>
